package com.my.vote.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.my.vote.R;
import com.my.vote.entity.EVoteItem;
import com.my.vote.entity.req.ReqVoteItem;
import com.sfh.lib.RxBusEventManager;
import com.sfh.lib.mvp.IPresenter;
import com.sfh.lib.ui.AbstractActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 功能描述:发布投票-添加选项
 *
 * @author Xiao Jingxiang 肖景翔
 * @date 2018/4/11
 */
public class AddVoteItemActivity extends AbstractActivity {

    public static void startUI(Context context, int size) {
        Intent intent = new Intent(context, AddVoteItemActivity.class);
        intent.putExtra("DATA", size);
        context.startActivity(intent);
    }

    @BindView(R.id.tvLeft)
    TextView tvLeft;
    @BindView(R.id.etTitle)
    EditText etTitle;
    @BindView(R.id.etDes)
    EditText etDes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_vote_item);
        ButterKnife.bind(this);
        tvLeft.setText("Add Item");
    }

    @OnClick({R.id.tvLeft, R.id.btOK})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvLeft:
                // 退出当前界面
                finish();
                break;
            case R.id.btOK:
                EVoteItem itemData = new EVoteItem();
                itemData.setSerialNumber(getIntent().getIntExtra("DATA", 1));
                itemData.setTitle(etTitle.getText().toString());
                itemData.setIntroduce(etDes.getText().toString());
                if (TextUtils.isEmpty(itemData.getTitle())) {
                    showToast("Please enter the title");
                    return;
                }
                if (TextUtils.isEmpty(itemData.getIntroduce())) {
                    showToast("Please enter a brief introduction");
                    return;
                }
                RxBusEventManager.postEvent(itemData);
                finish();
                break;
        }
    }

    @Override
    public IPresenter getPresenter() {
        return null;
    }
}
